
/* GCSx
** TOOLSELECT.CPP
**
** Tool selection popup dialogs
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#include "all.h"

ToolSelect::ToolSelect(SDL_Surface* tIconSurface, int myNumTools, const ToolIconStruct* toolStructs) : Dialog(blankString, 0, 0) { start_func
    assert(myNumTools);
    assert(toolStructs);
    
    iconSurface = tIconSurface;
    numTools = myNumTools;
    tools = toolStructs;
    
    Widget* w = NULL;
    
    for (int pos = 0; pos < numTools; ++pos) {
        w = new WButton(toolStructs[pos].id, iconSurface, toolStructs[pos].x, toolStructs[pos].y, 20, 20, Dialog::BUTTON_OK);
        w->setToolTip(toolStructs[pos].tooltip);
        w->addTo(this);
        
        if (pos % 4 == 3) arrangeRow();
    }
    arrangeRow();
}

ToolSelect::~ToolSelect() { start_func
}

int ToolSelect::run(int atX, int atY) { start_func
    return runModal(atX, atY);
}

int ToolSelect::getToolIcon(int id, int& iX, int& iY) const { start_func
    for (int pos = 0; pos < numTools; ++pos) {
        if (tools[pos].id == id) {
            iX = tools[pos].x;
            iY = tools[pos].y;
            return 1;
        }
    }
    
    return 0;
}

int ToolSelect::isTool(int id) const { start_func
    for (int pos = 0; pos < numTools; ++pos) {
        if (tools[pos].id == id) {
            return 1;
        }
    }
    
    return 0;
}



